<!doctype html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="学习笔记,docker,jenkins," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="前言公司之前的项目发布是通过jenkins自动发布的，只要在jenkins上选择项目，点击构建项目，项目就自动部署好了。对于开发人员来说这非常方便，只要修改好源码，提交到github中后，登录jenkins的Web界面，选择项目点击构建就行了。几经摸索后，我终于在自己的Mac上搭建成功了，期间碰到的问题大多是关于docker方面的，其中有个问题还没有从根本上解决，只是通过变通的方式使得部署成功，在">
<meta property="og:type" content="article">
<meta property="og:title" content="Mac上搭建jenkins+docker+maven+git自动部署">
<meta property="og:url" content="http://jieminblog.tk/2017/04/13/Mac上搭建jenkins-docker-maven-git自动部署/index.html">
<meta property="og:site_name" content="jiemin's Blog">
<meta property="og:description" content="前言公司之前的项目发布是通过jenkins自动发布的，只要在jenkins上选择项目，点击构建项目，项目就自动部署好了。对于开发人员来说这非常方便，只要修改好源码，提交到github中后，登录jenkins的Web界面，选择项目点击构建就行了。几经摸索后，我终于在自己的Mac上搭建成功了，期间碰到的问题大多是关于docker方面的，其中有个问题还没有从根本上解决，只是通过变通的方式使得部署成功，在">
<meta property="og:image" content="http://i4.buimg.com/567571/a7113335be68609d.png">
<meta property="og:image" content="http://i4.buimg.com/567571/c840a1c653d89e63.png">
<meta property="og:image" content="http://i2.muimg.com/567571/dc029c5d89602fd0.png">
<meta property="og:image" content="http://i4.buimg.com/567571/a62abcbe6a8c5bc0.png">
<meta property="og:image" content="http://i1.piimg.com/567571/fdb1104f47b60136.png">
<meta property="og:image" content="http://i4.buimg.com/567571/f3cb0d4ce0fe46b9.png">
<meta property="og:image" content="http://i1.piimg.com/567571/5589a02b3a4d9d66.png">
<meta property="og:image" content="http://i1.piimg.com/567571/9ca2d175cc847cc4.png">
<meta property="og:image" content="http://omdsjtsd2.bkt.clouddn.com/17-4-13/22437020-file_1492050771270_7ea.png">
<meta property="og:image" content="http://i1.piimg.com/567571/7c480aed24b44b84.png">
<meta property="og:image" content="http://i1.piimg.com/567571/561d033c068d5d78.png">
<meta property="og:image" content="http://omdsjtsd2.bkt.clouddn.com/17-4-13/67981561-file_1492050907930_12f64.png">
<meta property="og:updated_time" content="2017-04-13T03:02:34.405Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Mac上搭建jenkins+docker+maven+git自动部署">
<meta name="twitter:description" content="前言公司之前的项目发布是通过jenkins自动发布的，只要在jenkins上选择项目，点击构建项目，项目就自动部署好了。对于开发人员来说这非常方便，只要修改好源码，提交到github中后，登录jenkins的Web界面，选择项目点击构建就行了。几经摸索后，我终于在自己的Mac上搭建成功了，期间碰到的问题大多是关于docker方面的，其中有个问题还没有从根本上解决，只是通过变通的方式使得部署成功，在">
<meta name="twitter:image" content="http://i4.buimg.com/567571/a7113335be68609d.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://jieminblog.tk/2017/04/13/Mac上搭建jenkins-docker-maven-git自动部署/"/>





  <title> Mac上搭建jenkins+docker+maven+git自动部署 | jiemin's Blog </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  














  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">jiemin's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">本来无一物，何处惹尘埃</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://jieminblog.tk/2017/04/13/Mac上搭建jenkins-docker-maven-git自动部署/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="我爱的乌托邦">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/uploads/touxiang.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="jiemin's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Mac上搭建jenkins+docker+maven+git自动部署
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-04-13T10:56:34+08:00">
                2017-04-13
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>公司之前的项目发布是通过jenkins自动发布的，只要在jenkins上选择项目，点击构建项目，项目就自动部署好了。对于开发人员来说这非常方便，只要修改好源码，提交到github中后，登录jenkins的Web界面，选择项目点击构建就行了。几经摸索后，我终于在自己的Mac上搭建成功了，期间碰到的问题大多是关于docker方面的，其中有个问题还没有从根本上解决，只是通过变通的方式使得部署成功，在后文中将会提到。</p>
<a id="more"></a>
<h1 id="前置条件"><a href="#前置条件" class="headerlink" title="前置条件"></a>前置条件</h1><ol>
<li>已经安装好jenkins</li>
<li>已经安装好git</li>
<li>已经安装好docker,我这里使用的是docker for mac版本</li>
<li>有一个测试的项目，我这里使用的是springboot搭建的一个项目。</li>
</ol>
<h1 id="搭建步骤"><a href="#搭建步骤" class="headerlink" title="搭建步骤"></a>搭建步骤</h1><h2 id="jenkins上新建项目"><a href="#jenkins上新建项目" class="headerlink" title="jenkins上新建项目"></a>jenkins上新建项目</h2><p>登录jenkins后点击新建项目</p>
<p><img src="http://i4.buimg.com/567571/a7113335be68609d.png" alt=""></p>
<p>输入项目名称，选择构建项目类型，我这里选择了构建一个自由风格的软件项目</p>
<p><img src="http://i4.buimg.com/567571/c840a1c653d89e63.png" alt=""></p>
<p>源码管理选择git，输入git仓库地址，选择分支</p>
<p><img src="http://i2.muimg.com/567571/dc029c5d89602fd0.png" alt=""></p>
<p>构建选择shell构建，输入要执行的脚本</p>
<p><img src="http://i4.buimg.com/567571/a62abcbe6a8c5bc0.png" alt=""></p>
<p>完成上述步骤后点击保存</p>
<h1 id="为项目添加Dockerfile文件"><a href="#为项目添加Dockerfile文件" class="headerlink" title="为项目添加Dockerfile文件"></a>为项目添加Dockerfile文件</h1><figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">FROM</span> index.alauda.cn/library/java:<span class="number">7</span>u91</div><div class="line"><span class="keyword">COPY</span><span class="bash"> ./target/gx.jar /gx.jar</span></div><div class="line"><span class="keyword">ENV</span> TZ Asia/Shanghai</div><div class="line"><span class="keyword">ENTRYPOINT</span><span class="bash"> [<span class="string">"java"</span>, <span class="string">"-jar"</span>, <span class="string">"-Djava.security.egd=file:/dev/./urandom"</span>, <span class="string">"/gx.jar"</span>,<span class="string">"--logging.path=/var/log"</span>]</span></div></pre></td></tr></table></figure>
<p>添加后的目录结构如下</p>
<p><img src="http://i1.piimg.com/567571/fdb1104f47b60136.png" alt=""></p>
<h1 id="自动部署"><a href="#自动部署" class="headerlink" title="自动部署"></a>自动部署</h1><p>返回到主页面，点击构建按钮</p>
<p><img src="http://i4.buimg.com/567571/f3cb0d4ce0fe46b9.png" alt=""></p>
<p>进入控制台可以查看构建情况</p>
<p><img src="http://i1.piimg.com/567571/5589a02b3a4d9d66.png" alt=""></p>
<p>控制台最后，看到finished：success则表示构建成功</p>
<p><img src="http://i1.piimg.com/567571/9ca2d175cc847cc4.png" alt=""></p>
<h1 id="遇到的问题"><a href="#遇到的问题" class="headerlink" title="遇到的问题"></a>遇到的问题</h1><ol>
<li>docker registry不能push成功</li>
</ol>
<p><img src="http://omdsjtsd2.bkt.clouddn.com/17-4-13/22437020-file_1492050771270_7ea.png" alt=""></p>
<p>解决办法: advance中添加docker私服地址</p>
<p><img src="http://i1.piimg.com/567571/7c480aed24b44b84.png" alt=""></p>
<p><img src="http://i1.piimg.com/567571/561d033c068d5d78.png" alt=""></p>
<ol>
<li>docker远程管理失败</li>
</ol>
<p><img src="http://omdsjtsd2.bkt.clouddn.com/17-4-13/67981561-file_1492050907930_12f64.png" alt=""></p>
<p>解决办法:由于我的docker版本是docker for mac，我查了很多资料，基本都是linux的docker版本远程管理解决方案，没有mac版本的方案。所以就退而求其次，把<code>-H 192.168.1.207</code>给删除了，相当于访问服务器本机的资源，如果有多台服务器，那就必须通过<code>-H ip</code>来管理了。</p>
<h1 id="后记"><a href="#后记" class="headerlink" title="后记"></a>后记</h1><p>这次的搭建中新学到了不少的东西，比如docker的私服，docker的远程管理，dockerfile文件等等，其中mac上的远程管理我暂时还未能实现。我打算去centos服务器中再去从头搭建一次jenkins+docker+git+maven自动部署，巩固所学知识的同时看看mac和centos上搭建的区别，并在centos上实现docker的远程管理。</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/学习笔记/" rel="tag"># 学习笔记</a>
          
            <a href="/tags/docker/" rel="tag"># docker</a>
          
            <a href="/tags/jenkins/" rel="tag"># jenkins</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/04/06/git学习笔记/" rel="next" title="git学习笔记">
                <i class="fa fa-chevron-left"></i> git学习笔记
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/04/18/学习笔记－使用poi替换word内容/" rel="prev" title="学习笔记－使用poi替换word内容">
                学习笔记－使用poi替换word内容 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/uploads/touxiang.jpeg"
               alt="我爱的乌托邦" />
          <p class="site-author-name" itemprop="name">我爱的乌托邦</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#前置条件"><span class="nav-number">2.</span> <span class="nav-text">前置条件</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#搭建步骤"><span class="nav-number">3.</span> <span class="nav-text">搭建步骤</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#jenkins上新建项目"><span class="nav-number">3.1.</span> <span class="nav-text">jenkins上新建项目</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#为项目添加Dockerfile文件"><span class="nav-number">4.</span> <span class="nav-text">为项目添加Dockerfile文件</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#自动部署"><span class="nav-number">5.</span> <span class="nav-text">自动部署</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#遇到的问题"><span class="nav-number">6.</span> <span class="nav-text">遇到的问题</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#后记"><span class="nav-number">7.</span> <span class="nav-text">后记</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">我爱的乌托邦</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    
    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	





  





  





  



  
  

  

  

  

  


  

</body>
</html>
